/*
 *    Copyright © OpenAtom Foundation.
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package com.inspur.edp.bff.spi;

import com.inspur.edp.bff.api.manager.IFSAction;
import com.inspur.edp.bff.api.manager.IFSManagerContext;

import java.util.Map;

public class AbstractFSManager {

    private IFSManagerContext context;

    /**
     * 管理器上下文{@link IFSManagerContext}
     */
    protected IFSManagerContext getContext() {
        return context;
    }

    public final void setContext(IFSManagerContext context) {
        this.context = context;
    }

    /**
     * 执行操作
     * {@link TResult}要执行的操作的返回值类型
     *
     * @param action 要执行的操作
     * @return 操作的执行结果
     */
    protected final <TResult> TResult executeAction(IFSAction<TResult> action) {
        return context.executeAction(action);
    }

    protected final <TResult> TResult executeAction(IFSAction<TResult> action, String actionId, String actionCode
            , Map<String, Object> parameters) {
        return context.executeAction(action, actionId, actionCode, parameters, false);
    }

    protected final <TResult> TResult executeAction(IFSAction<TResult> action, String actionId, String actionCode
            , Map<String, Object> parameters, boolean autoSave) {
        return context.executeAction(action, actionId, actionCode, parameters, autoSave);
    }

    protected final void ProcessResponse() {
        context.processResponse();
    }

    @Deprecated
    /** use save instea*/
    protected final void Save() {
        save();
    }

    protected final void save() {
        getContext().getLcp().save();
    }
}
